package com.kaishengit.service;


import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.kaishengit.dao.ContactDao;
import com.kaishengit.dao.core.DateUtil;
import com.kaishengit.pojo.Contact;
@Transactional
public class ContactService {
	private ContactDao contactDao;
	

	public void save(Contact contact) {
		contact.setCreatetime(DateUtil.getNow());
		contactDao.save(contact);
	}
	public void setContactDao(ContactDao contactDao) {
		this.contactDao = contactDao;
	}
	
	public List<Contact> findAllByUserid(String userid) {
		String hql="from Contact where userid=? order by createtime desc";
		return contactDao.find(hql, userid);
	}
	public Contact findById(String contactid) {
		return contactDao.findByUnique("id", contactid);
	}
	public void edit(Contact con) {
		contactDao.save(con);
	}
	public List<Contact> findAllContactByUserid(String userid) {
		String hql="from Contact where userid=? and name!=company order by createtime desc";
		return contactDao.find(hql, userid);
	}
	public List<Contact> findAllCompanyByUserid(String userid) {
		String hql="from Contact where userid=? and name=company order by createtime desc";
		return contactDao.find(hql, userid);
	}
	public void del(Contact contact) {
		contactDao.del(contact);
	}
	
	
	
	
}
